/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.fatecpg.songs.entity;

import br.com.fatecpg.songs.entity.util.Searchable;
import br.com.fatecpg.songs.entity.util.Securable;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.IndexColumn;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 *
 * @author Marcos
 */
@SequenceGenerator(name="SEQALBUM", sequenceName="SEQALBUM", allocationSize=1, initialValue=1)
@Entity(name="Album")
@Table(name="TB_ALBUM")
public class Album implements Securable, Searchable{
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="SEQALBUM")
    @Column(name="id")
    private Long id;
    
    @Column(name = "title")
    private String title;

    @Column(name = "album_year")
    private int year;
    
    @ManyToOne
    @JoinColumn(name = "id_recorder", referencedColumnName = "id")
    private Recorder recorder;
    
    @ManyToOne
    @JoinColumn(name = "id_artist", referencedColumnName = "id")
    private Artist artist;
        
    @OneToMany(mappedBy = "album")    
    private List<Song> songs;
    
    @ManyToOne
    @JoinColumn(name = "id_updater", referencedColumnName = "id")
    private User updaterUser;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_update")
    private Date lastUpdate;

    public Album() {
        artist = new Artist();
        recorder = new Recorder();
    }
    
    @Override
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public Recorder getRecorder() {
        return recorder;
    }

    public void setRecorder(Recorder recorder) {
        this.recorder = recorder;
    }

    public Artist getArtist() {
        return artist;
    }

    public void setArtist(Artist artist) {
        this.artist = artist;
    }

    public List<Song> getSongs() {
        return songs;
    }

    public void setSongs(List<Song> songs) {
        this.songs = songs;
    }

    @Override
    public User getUpdaterUser() {
        return updaterUser;
    }

    @Override
    public void setUpdaterUser(User updaterUser) {
        this.updaterUser = updaterUser;
    }

    @Override
    public Date getLastUpdate() {
        return lastUpdate;
    }

    @Override
    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }        
}
